// 中国剩余定理
// m1, m2, m3 ... 两两互质
// 测试链接 ：https://www.luogu.com.cn/problem/P1495
// 相关帖子 ：https://www.cnblogs.com/dx123/p/16739214.html
// 相关帖子 ：https://oi-wiki.org/math/number-theory/crt/
// 提交以下的code，可以直接通过

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int MAXN = 11;
ll n, a[MAXN], b[MAXN];

ll exgcd(ll a, ll b, ll& x, ll& y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1, d;
    d = exgcd(b, a % b, x1, y1);
    x = y1, y = x1 - a / b * y1;
    return d;
}

ll CRT(ll* m, ll* r)
{
    ll M = 1, ans = 0;
    for(int i = 1; i <= n; ++i) M *= m[i];
    for(int i = 1; i <= n; ++i)
    {
        ll c = M / m[i], x, y;
        // cx ≡ 1 (mod m[i])
        exgcd(c, m[i], x, y);
        ans = (ans + r[i] * c * x % M) % M;
    }
    return (ans % M + M) % M;
}

int main()
{
    scanf("%lld", &n);
    for(int i = 1; i <= n; ++i)
    {
        scanf("%lld%lld", a + i, b + i);
    }
    printf("%lld\n", CRT(a, b));

    return 0;
}